{{--继承模板--}}
@extends('admin.layouts.common')
@section('content')
    <link rel="stylesheet" type="text/css" href="{{ asset('common/layui-formSelects-master/dist/formSelects-v4.css') }}"/>
    <style>
        div[xm-select-skin=default] dl dd.xm-select-this:not(.xm-dis-disabled) i {
            color: #177ce3;
        }
        .xm-select-parent dl dd.xm-select-this div i {
            color: #177ce3;
        }
        .xm-form-checkbox > i {
            border: 1px solid #177ce3;

        }
        div[xm-select-skin="default"] dl dd:not(.xm-dis-disabled) i {
            border-color: #177ce3;
        }
    </style>
    <blockquote class="layui-elem-quote layui-elem-quote-blue" style="border-left: 5px solid #000000;background: #fff;">
    <span>
        &nbsp;&nbsp;&nbsp;1、《控/方》：意思是 控制器/方法; 例如 Sys/sysList<br/>
        &nbsp;&nbsp;&nbsp;2、图标名称为左侧导航栏目的图标样式，具体可查看<a href="https://www.iconfont.cn/" target="_blank" style="color:#FF0000"> Iconfont </a>图标<br>
           &nbsp;&nbsp;&nbsp;3、图标写入：<xmp style="display: inline;font-family: '微软雅黑';"><i class="iconfont icon-tianjia2"></i></xmp>
        (只需填入：icon-tianjia2)
    </span>
    </blockquote>
    <br>
    <div class="layui-anim layui-anim-up">
        <form class="layui-form">
            <div class="layui-container">
                <div class="layui-row">
                    <div class="layui-form-item">
                        <label class="layui-form-label">父级</label>
                        <div class="layui-input-block">
                            <select name="pid" lay-verify="required" lay-filter="pid" xm-select="selectId" xm-select-skin="default" xm-select-radio="" xm-select-search="" xm-select-search-type="dl">
                                <option value="0" {{($pid != '' && $pid == 0 && is_numeric($pid))?"selected": ""}}>默认顶级</option>
                                @foreach($admin_rule as $vo)
                                    <option value="{{$vo['id']}}" {{($vo['id'] == $pid)?"selected": ""}}>{{$vo['lefthtml']}}{{$vo['title']}}</option>
                                @endforeach
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">权限名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="title" lay-verify="required" placeholder="请输入权限名称" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">控制器/方法</label>
                            <div class="layui-input-inline">
                                <input type="text" name="href" lay-verify="required" placeholder="请输入控制器/方法" class="layui-input">
                                {{--  <div class="layui-form-mid layui-word-aux">
                                      <span style="color: red">*</span> 首字母大写，允许2-80字节，允许字母数字
                                  </div>--}}
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">图标</label>
                            <div class="layui-input-inline">
                                <input type="text" name="icon" placeholder="请输入图标名称" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">排序</label>
                            <div class="layui-input-inline">
                                <input type="text" name="sort" value="50" placeholder="请输入排序编号" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">菜单状态</label>
                        <div class="layui-input-inline">
                            <input type="radio" name="menustatus" lay-filter="menustatus" checked value="1" title="开启">
                            <input type="radio" name="menustatus" lay-filter="menustatus" value="0" title="关闭">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button type="submit" class="layui-btn layui-btn-black" lay-submit="" lay-filter="ruleadd">添加</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <script src="{{asset('layuiadmin/layui/layui.js')}}"></script>
    <script src=" {{ asset('common/layui-formSelects-master/dist/formSelects-v4.js') }}" type="text/javascript" charset="utf-8"></script>
    <script>
        layui.use(['form','layer','element'], function(){
            var form = layui.form
                ,layer = layui.layer
                ,element = layui.element
                ,$ = layui.jquery;
            var _token =  $('meta[name="csrf-token"]').attr('content');

            //监听提交
            form.on('submit(ruleadd)', function(data){
                /*var href = data.field.href;
                if(!(/^[A-Z][a-zA-Z0-9/]{1,79}$/).test(href)){
                    layer.msg("控制器/方法格式错误");
                    return false;
                };*/
                data.field._token = _token;
                $.post("{{url('admin/auth/ruleadd')}}",data.field,function(res){
                    if(res.code == 1){
                        layer.msg(res.msg,function () {
                            window.location.reload();
                        });
                    }else{
                        layer.msg(res.msg);
                    }
                },'json')
                return false;
            });
        });
    </script>
@endsection